package com.hyfrogx.modules.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyfrogx.common.exception.ServiceException;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.manage.entity.payrecord.HyPayRecord;
import com.hyfrogx.modules.manage.service.HyPayRecordService;
import com.hyfrogx.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：Li9527
 * @date ：Created in 2019-10-16 14:57
 * @description：${description}
 * @modified By：
 * @version: 1.0.0
 */
@RestController
@RequestMapping("pay/record")
@Api(value = "消费明细controller", tags = {"后台-消费明细"})
public class PayRecordController extends AbstractController {

    @Autowired
    HyPayRecordService hyPayRecordService;

    /**
     * V2.0获得个人的支付记录
     *
     * @return
     */
    @RequestMapping(value = "history/get")
    public R getNewChargeHistory(@RequestBody Map<String,Object> params) {

        if (params.get("uid") == null) {
            return R.error("用户ID不能为空");
        }
        try {
            List<HyPayRecord> list = hyPayRecordService.selectPageByConditions(new QueryExt(params));
            for (int i= 0; i < list.size(); i++) {
                // 如果uid = uid 是付款
                if(list.get(i).getUid().equals(params.get("uid"))){
                    list.get(i).setMoney(-list.get(i).getMoney());
                    list.get(i).setTotal(-list.get(i).getTotal());
                }
            }
            return R.ok().put("data",list);
        } catch (ServiceException e) {
            return R.error(e.getMessage());
        }
    }












}
